package cn.bx.bid.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;

import cn.bx.bid.entity.User;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

//映射user.xml中的操作
@Cacheable
@CacheConfig(cacheNames = "user",keyGenerator = "keyg")
public interface UserDao {


	User get(long id);

	////////////////////////////
	//缓存了数据,删除了一条,db中没有,缓存中还在...CUD操作之后,一般要重建缓存(1中方案:清除,再缓存;第二种方案:直接更新缓存)
	@CacheEvict(value = "user",allEntries = true)
	int add(User u);
	@CacheEvict(value = "user",allEntries = true)
	int update(User u);
	@CacheEvict(value = "user",allEntries = true)
	int del(long id);
	/* 批量删除 */
	@CacheEvict(value = "user",allEntries = true)
	int batchDel(@Param("ids") long[] ids);
	/////////////////////////////////////

	//public List<User> find(@Param("sex") int sex);
	//@Cacheable
	public List<User> search(@Param("pageNo") int pageNo, @Param("pageSize") int limit, @Param("name") String name,
                             @Param("start") Date start, @Param("end") Date end);

	public int searchTotal(@Param("name") String name, @Param("start") Date start, @Param("end") Date end);

    int checkUserNameRepeat(@Param("id") Long id, @Param("userName") String userName);

    User login(@Param("userName") String username, @Param("pass") String password);
}
